package com.zhang.hadoop.testMain;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author ：zhangyufei.zhang
 * @date ：Created in 2021-08-20 11:05
 * @description：
 */
public class Test5 {

    public static volatile String flag = "A";
    public static AtomicInteger atomicInteger = new AtomicInteger(0);

    public static void main(String[] args) {

        new Thread(() -> {
            int i = 0;
            boolean flag1 = true;
            while (flag1) {
                while ("A".equals(flag) && i <= 10) {
                    for (int j = 1; j <= 5; j++) {
                        System.out.println("AA" + "\t" + atomicInteger.addAndGet(1));
                    }
                    flag = "B";
                    i++;
                    if (i == 10) {
                        flag1 = false;
                    }
                }
            }

        }, "A").start();

        new Thread(() -> {
            int i = 0;
            boolean flag1 = true;
            while (flag1) {
                while ("B".equals(flag) && i <= 10) {
                    for (int j = 1; j <= 5; j++) {
                        System.out.println("BB" + "\t" + atomicInteger.addAndGet(1));
                    }
                    flag = "C";
                    i++;
                    if (i == 10) {
                        flag1 = false;
                    }
                }
            }
        }, "B").start();

        new Thread(() -> {
            int i = 0;
            boolean flag1 = true;
            while (flag1) {
                while ("C".equals(flag) && i <= 10) {
                    for (int j = 1; j <= 5; j++) {
                        System.out.println("CC" + "\t" + atomicInteger.addAndGet(1));
                    }
                    flag = "A";
                    i++;
                    if (i == 10) {
                        flag1 = false;
                    }
                }
            }
        }, "C").start();

    }
}
